/*
 * CPScene.java
 *
 * Created on 2010-10-26, 21:25:11
 */

package JET.CenterPanels;

import JET.Centers.ControlCenter;
import JET.Centers.Graphics.GraphicMode;
import JET.graphics.GraphicPanel;
import JET.mygui.CenterTabsPane.CenterTabsPaneTab;
import JET.mygui.CenterTabsPane.TabType;
import JET.mygui.TabsPane;
import JET.mygui.TabsPane.TabListener;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 *
 * @author 057Ry
 */
public class CPScene extends javax.swing.JPanel implements CenterTabsPaneTab {

    ControlCenter CC = ControlCenter.getInstance();

    private String sceneName = "";
    private GraphicMode graphicMode = GraphicMode.Unknown;
    private boolean isTabOpened = false;

    /**
     * References to graphic panels of this scene tab.
     */
    public GraphicPanel swingGP, joglGP;

    /** Creates new form CPScene */
    public CPScene() {
        initComponents();

        addTabSelectionListener( new TabListener() {
            public void tabSelected(TabsPane tp) {
                System.out.println("tab seleted: "+getTitle());
            }

            public void tabFocused(TabsPane tp) {
                if (!CC.GUIC.getCurrentSceneName().equals(sceneName))
                    CC.GUIC.setCurrentScene(sceneName);
            }
        });
    }

    public TabType getTabType() {
        return TabType.GraphicPanel;
    }

    public String getTitle() {
        return !sceneName.equals("") ? sceneName : "Scene";
    }


    public boolean isTabOpened() {
        return isTabOpened;
    }
    public void setTabOpened(boolean value) {
        isTabOpened = value;
    }

    public String getSceneName() {
        return sceneName;
    }
    public void setSceneName(String name) {
        sceneName = name;
    }

    public GraphicPanel getGraphicPanel() {
        switch (graphicMode) {
            case Swing :
                return swingGP;
            case OpenGL :
                return joglGP;
            default:
                return null;
        }
    }

    public GraphicMode getGraphicMode() {return graphicMode;}
    public void setGraphicMode(GraphicMode gm) {graphicMode = gm;}

    ////////////////////////////////////////////////////////////////////////////
    //             T A B   S E L E C T I O N   L I S T E N E R S              //
    ////////////////////////////////////////////////////////////////////////////

    ArrayList<TabListener> tabListeners = new ArrayList<TabListener>();

    public void addTabSelectionListener(TabListener l) {
        if (!tabListeners.contains(l))
            tabListeners.add(l);
    }
    public void removeTabSelectionListener(TabListener l) {
        tabListeners.remove(l);
    }
    public void notifyTabSelected(TabsPane tp) {
        for(TabListener l : tabListeners)
            l.tabSelected(tp);
    }
    public void notifyTabFocused(TabsPane tp) {
        for(TabListener l : tabListeners)
            l.tabFocused(tp);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        startStopToggleButton = new javax.swing.JToggleButton();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        gravityToggleButton = new javax.swing.JToggleButton();
        jToggleButton6 = new javax.swing.JToggleButton();
        jToggleButton5 = new javax.swing.JToggleButton();
        jToggleButton4 = new javax.swing.JToggleButton();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton7 = new javax.swing.JToggleButton();
        jToggleButton8 = new javax.swing.JToggleButton();
        jToggleButton9 = new javax.swing.JToggleButton();
        jToggleButton10 = new javax.swing.JToggleButton();
        jToggleButton11 = new javax.swing.JToggleButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        gpContainer = new javax.swing.JPanel();

        jPanel1.setMaximumSize(new java.awt.Dimension(30, 32767));
        jPanel1.setMinimumSize(new java.awt.Dimension(30, 10));
        jPanel1.setOpaque(false);
        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));

        startStopToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/start_animation.PNG"))); // NOI18N
        startStopToggleButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        startStopToggleButton.setMaximumSize(new java.awt.Dimension(25, 25));
        startStopToggleButton.setMinimumSize(new java.awt.Dimension(10, 10));
        startStopToggleButton.setPreferredSize(new java.awt.Dimension(25, 25));
        startStopToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startStopToggleButtonActionPerformed(evt);
            }
        });
        jPanel1.add(startStopToggleButton);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/stop_animation.PNG"))); // NOI18N
        jButton1.setMaximumSize(new java.awt.Dimension(25, 25));
        jButton1.setMinimumSize(new java.awt.Dimension(10, 10));
        jButton1.setPreferredSize(new java.awt.Dimension(25, 25));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 10, Short.MAX_VALUE)
        );

        jPanel1.add(jPanel3);

        gravityToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/gravity.PNG"))); // NOI18N
        gravityToggleButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        gravityToggleButton.setMaximumSize(new java.awt.Dimension(25, 25));
        gravityToggleButton.setMinimumSize(new java.awt.Dimension(10, 10));
        gravityToggleButton.setPreferredSize(new java.awt.Dimension(25, 25));
        gravityToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gravityToggleButtonActionPerformed(evt);
            }
        });
        jPanel1.add(gravityToggleButton);

        jToggleButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/damping.PNG"))); // NOI18N
        jToggleButton6.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton6.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton6.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton6.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton6ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton6);

        jToggleButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/force.PNG"))); // NOI18N
        jToggleButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton5.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton5.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton5.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton5ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton5);

        jToggleButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/velocity.PNG"))); // NOI18N
        jToggleButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton4.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton4.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton4.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton4);

        jToggleButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/follow_camera.PNG"))); // NOI18N
        jToggleButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton3.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton3.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton3.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton3);

        jToggleButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/main_grid.PNG"))); // NOI18N
        jToggleButton7.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton7.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton7.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton7.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton7ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton7);

        jToggleButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/help_grid.PNG"))); // NOI18N
        jToggleButton8.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton8.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton8.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton8.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton8ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton8);

        jToggleButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/action_frame.PNG"))); // NOI18N
        jToggleButton9.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton9.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton9.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton9.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton9ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton9);

        jToggleButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/collision_detection.PNG"))); // NOI18N
        jToggleButton10.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton10.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton10.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton10.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton10ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton10);

        jToggleButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/collision_answer.PNG"))); // NOI18N
        jToggleButton11.setMargin(new java.awt.Insets(0, 0, 0, 0));
        jToggleButton11.setMaximumSize(new java.awt.Dimension(25, 25));
        jToggleButton11.setMinimumSize(new java.awt.Dimension(10, 10));
        jToggleButton11.setPreferredSize(new java.awt.Dimension(25, 25));
        jToggleButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton11ActionPerformed(evt);
            }
        });
        jPanel1.add(jToggleButton11);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/clear_scene.PNG"))); // NOI18N
        jButton2.setMaximumSize(new java.awt.Dimension(25, 25));
        jButton2.setMinimumSize(new java.awt.Dimension(10, 10));
        jButton2.setPreferredSize(new java.awt.Dimension(25, 25));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/zero_velocities.PNG"))); // NOI18N
        jButton3.setMaximumSize(new java.awt.Dimension(25, 25));
        jButton3.setMinimumSize(new java.awt.Dimension(10, 10));
        jButton3.setPreferredSize(new java.awt.Dimension(25, 25));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JET/Images/random_velocities.PNG"))); // NOI18N
        jButton4.setMaximumSize(new java.awt.Dimension(25, 25));
        jButton4.setMinimumSize(new java.awt.Dimension(10, 10));
        jButton4.setPreferredSize(new java.awt.Dimension(25, 25));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton4);

        gpContainer.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        gpContainer.setOpaque(false);
        gpContainer.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(gpContainer, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 669, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(gpContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void startStopToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startStopToggleButtonActionPerformed
        if (startStopToggleButton.isSelected()) {
            startStopToggleButton.setIcon(new ImageIcon(getClass().getResource("/JET/Images/stop_aniamtion.PNG")));
            CC.play(sceneName);
        }
        else {
            startStopToggleButton.setIcon(new ImageIcon(getClass().getResource("/JET/Images/start_aniamtion.PNG")));
            CC.stop(sceneName);
        }
    }//GEN-LAST:event_startStopToggleButtonActionPerformed

    private void jToggleButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton3ActionPerformed

    private void jToggleButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton4ActionPerformed

    private void jToggleButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton5ActionPerformed

    private void jToggleButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton6ActionPerformed

    private void gravityToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gravityToggleButtonActionPerformed
        CC.getScene(sceneName).getJETContext().setApplyGravity(gravityToggleButton.isSelected());
    }//GEN-LAST:event_gravityToggleButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jToggleButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton7ActionPerformed

    private void jToggleButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton8ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton8ActionPerformed

    private void jToggleButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton9ActionPerformed

    private void jToggleButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton10ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton10ActionPerformed

    private void jToggleButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton11ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleButton11ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JPanel gpContainer;
    private javax.swing.JToggleButton gravityToggleButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JToggleButton jToggleButton10;
    private javax.swing.JToggleButton jToggleButton11;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton4;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JToggleButton jToggleButton6;
    private javax.swing.JToggleButton jToggleButton7;
    private javax.swing.JToggleButton jToggleButton8;
    private javax.swing.JToggleButton jToggleButton9;
    private javax.swing.JToggleButton startStopToggleButton;
    // End of variables declaration//GEN-END:variables

}
